package com.chat.admin.controller;


import com.chat.admin.annotate.IsNumeric;
import com.chat.admin.domain.DTO.ADD.AddRoleDTO;
import com.chat.admin.domain.DTO.EDIT.EditRoleDTO;
import com.chat.admin.domain.DTO.RoleDTO;
import com.chat.admin.domain.VO.RoleVO;
import com.chat.admin.service.IRoleService;
import com.chat.common.entity.Role;
import com.chat.common.form.ListForm;
import com.chat.common.vo.R;
import jakarta.validation.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 管理员角色模块
 */
@RestController
@Validated
@RequestMapping("/admin/system/role")
public class RoleController {

    @Autowired
    IRoleService iRoleService;

    /**
     * 获取角色列表
     * @param roleDTO
     * @return
     */
    @PostMapping("/list")
    public R<ListForm<RoleVO>> getRoleList(@Validated @RequestBody RoleDTO roleDTO) {
        return iRoleService.getRoleList(roleDTO);
    }

    /**
     * 添加角色
     * @param addroleDTO
     * @return
     */
    @PostMapping("/add")
    public R getRoleList(@Validated @RequestBody AddRoleDTO addroleDTO) {
        return iRoleService.insertRole(addroleDTO);
    }

    /**
     * 更新角色
     * @param editroleDTO
     * @return
     */
    @PostMapping("/edit")
    public R getRoleList(@Validated @RequestBody EditRoleDTO editroleDTO) {
        return iRoleService.updateRole(editroleDTO);
    }
    /**
     * 禁用角色
     * @param ID
     * @return
     */
    @GetMapping("/disableRole")
    public R<?> DisableAccount(@RequestParam @NotBlank(message = "ID不能为空") @IsNumeric(message = "ID不是数字") String ID) {
        return iRoleService.DisableRole(Long.valueOf(ID));
    }

    /**
     * 启用角色
     * @param ID
     * @return
     */
    @GetMapping("/enableRole")
    public R<?> EnableAccount(@RequestParam @NotBlank(message = "ID不能为空") @IsNumeric(message = "ID不是数字") String ID){
        return iRoleService.EnableRole(Long.valueOf(ID));
    }

    /**
     * 获取可用的角色List
     * @return
     */
    @GetMapping("/available_role_list")
    public R<List<Role>> getStateRoleList(){
        return R.succeed(iRoleService.getStateRoles());
    }

    /**
     * 获取可用角色的map
     * @return
     */
    @GetMapping("/available_role_map")
    public R<Map<Long, Role>> getStateRoleMap(){
        return R.succeed(iRoleService.getStateRolesMap());
    }
}
